var e = require;
var t = module;
var o = exports;
var n =
    (this && this.__spreadArrays) ||
    function () {
        for (var e = 0, t = 0, o = arguments.length; t < o; t++) e += arguments[t].length;
        var n = Array(e),
            i = 0;
        for (t = 0; t < o; t++) for (var r = arguments[t], a = 0, c = r.length; a < c; a++, i++) n[i] = r[a];
        return n;
    };
Object.defineProperty(o, "__esModule", {value: !0});
var i = (function () {
    function e() {
        this.callbacks = {};
    }
    e.prototype.on = function (e, t, o, n) {
        var i = this.callbacks[e];
        if (i)
            for (var r = 0; r < i.length; r++) {
                var a = i[r];
                if (a.callback === t && a.thisArg === o) return;
            }
        else {
            i = [];
            this.callbacks[e] = i;
        }
        var c = {callback: t, thisArg: o};
        n && (c.once = n);
        i.push(c);
    };
    e.prototype.once = function (e, t, o) {
        this.on(e, t, o, !0);
    };
    e.prototype.onArr = function (e, t, o, n) {
        for (var i = 0; i < e.length; i++) this.on(e[i], t, o, n);
    };
    e.prototype.off = function (e, t, o) {
        if (t) {
            var n = this.callbacks[e];
            if (n) {
                for (var i = n.length - 1; i >= 0; i--) {
                    var r = n[i];
                    if (r.callback === t && r.thisArg === o) {
                        n.splice(i, 1);
                        break;
                    }
                }
                0 === n.length && delete this.callbacks[e];
            }
        } else delete this.callbacks[e];
    };
    e.prototype.offArr = function (e, t, o) {
        for (var n = 0; n < e.length; n++) this.off(e[n], t, o);
    };
    e.prototype.offTarget = function (e) {
        if (e)
            for (var t in this.callbacks) {
                var o = this.callbacks[t];
                if (o) {
                    for (var n = o.length - 1; n >= 0; n--)
                        if (o[n].thisArg === e) {
                            o.splice(n, 1);
                            break;
                        }
                    0 === o.length && delete this.callbacks[t];
                }
            }
    };
    e.prototype.log = function () {
        console.log("EventBase ----------------- this.callbacks", this.callbacks);
    };
    e.prototype.offAll = function () {
        this.callbacks = {};
    };
    e.prototype.emit = function (e) {
        for (var t, o = [], i = 1; i < arguments.length; i++) o[i - 1] = arguments[i];
        var r = this.callbacks[e];
        if (r)
            for (var a = 0; a < r.length; a++) {
                var c = r[a];
                if (c.once) {
                    this.off(e, c.callback, c.thisArg);
                    a--;
                }
                (t = c.callback).call.apply(t, n([c.thisArg, e], o));
            }
    };
    return e;
})();
o.default = i;
